import axios from '@/assets/js/axios'
import utils from '@/assets/js/utils'
// import res from '@/assets/js/result'
import {
  Message
} from 'element-ui'

// 获取标签列表
function getTabList() {
  let markMapId = utils.getMarkMapId();
  return new Promise(resolve => {
    const url = 'api/landmarkCat';
    axios.getUrl(url, {
      landmarkMap_id: markMapId
    }).then(rst => {
      // console.log(rst)
      errMessage(rst)
      resolve(rst);
    })
  })
}

function getFeatureList() {
  let markMapId = utils.getMarkMapId();
  return new Promise(resolve => {
    const url = 'api/landmarkDataWithMarks';
    axios.getUrl(url, {
      landmarkMap_id: markMapId
    }).then(rst => {
      errMessage(rst)
      resolve(rst);
    })
  })
}

// 根据标签类别,获取地图标点列表
// function getFeatureList(data = {}) {
//   let markMapId = utils.getMarkMapId();
//   return new Promise(resolve => {
//     const url = 'api/landmarkMarks';
//     axios.getUrl(url, { ...data,
//       landmarkMap_id: markMapId
//     }).then(rst => {
//       errMessage(rst);
//       debugger
//       resolve(rst);
//     })
//   })
// }

// 根据标签类别,获取标注图片
function getIconList(data) {
  let markMapId = utils.getMarkMapId();
  return new Promise(resolve => {
    const url = 'api/landmarkIcon';
    axios.getUrl(url, { ...data,
      landmarkMap_id: markMapId
    }).then(rst => {
      errMessage(rst);
      resolve(rst)
    })
  })
}

// 获取所有待添加的标注点位
function getMarkDatas(data) {
  let markMapId = utils.getMarkMapId();
  return new Promise(resolve => {
    const url = 'api/landmarkDatas';
    axios.getUrl(url, {
      landmarkMap_id: markMapId
    }).then(rst => {
      errMessage(rst);
      resolve(rst);
    })
  })
}

function errMessage(rst) {
  if (rst.code != 200) {
    Message({
      message: rst.msg,
      type: 'error',
      duration: 1000,
      showClose: true
    })
  }
}

export default {
  getTabList,
  getFeatureList,
  getIconList,
  getMarkDatas
}
